package vip.buddha.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import vip.buddha.entity.Account;
import vip.buddha.mapper.AccountMapper;

@Service
public class AccountService {
    @Autowired
    private AccountMapper accountMapper;

    public int updateByUserId(Integer userId, Account account) {
        QueryWrapper<Account> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        Account one = accountMapper.selectOne(wrapper);
        if (one.getMoney() < account.getMoney()) {
            return 0;
        }
        Account a = new Account();
        a.setId(one.getId());
        a.setMoney(one.getMoney() - account.getMoney());
        return accountMapper.updateById(a);
    }
}
